<template>
  <div v-loading="loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading">
    <div class="storage_menu">
      <div class="storage_box" v-for="item in this.$store.state.storage.list" :key="item.Id">
        <!-- 存储的icon -->

        <div class="storage_box_left">
          <img src="../../assets/static/image/storage.png" alt srcset width="60" />
        </div>

        <!-- 右div -->
        <div class="storage_box_right">
          <!-- 顶部div -->
          <div @mouseenter="show(item.Id)" @mouseleave="showout" class="storage_box_more">
            <div>
              <img src="../../assets/static/image/more.png" alt width="26" />
            </div>
            <div v-show="showQr===item.Id" class="storage_box_fun">
              <ul>
                <li @click="tickets(item.Id)">
                  <span class="el-icon-tickets"></span>属性
                </li>
                <li @click="isdelete(item.Id,item.bucket_name)">
                  <span class="el-icon-delete"></span>删除
                </li>
              </ul>
            </div>
          </div>

          <!-- 底部div -->
          <div class="storage_box_name">{{ item.alias }}</div>
        </div>
      </div>
    </div>
    <el-dialog
      title="存储空间信息"
      :visible.sync="dialogVisible"
      width="80%"
      :modal="true"
      :close-on-click-modal="false"
    >
      <div class="descriptions">
        <el-descriptions class="margin-top" border>
          <el-descriptions-item label="Id">{{ storageInfo.bucket_id }}</el-descriptions-item>
          <el-descriptions-item label="名称">{{ storageInfo.alias }}</el-descriptions-item>
          <el-descriptions-item label="access_key">{{ storageInfo.access_key }}</el-descriptions-item>
          <el-descriptions-item label="secret_key">{{ storageInfo.secret_key }}</el-descriptions-item>
          <el-descriptions-item label="zone">{{storageInfo.zone}}</el-descriptions-item>
          <el-descriptions-item label="bucket_name">{{ storageInfo.bucket_name }}</el-descriptions-item>
          <el-descriptions-item label="domain_name">{{ storageInfo.domain_name }}</el-descriptions-item>
        </el-descriptions>
      </div>

    </el-dialog>
  </div>
</template>

<script>
import { ListBuckets, Tickets, IsDelete } from "@/utils/http";

export default {
  data() {
    return {
      storageInfo: {},
      // shopShow: false,
      Show: false,
      Limit: 1,
      Page: 10,
      showQr: null,
      dialogVisible: false,
      loading: false // 删除加载动画
    };
  },
  methods: {
    listBockets() {
      this.loading = true;
      ListBuckets(this.Limit, this.Page)
        .then(res => {
          this.loading = false;
          if (res.data.code == 200) {
            this.$store.commit("setSorage", res.data.data);
          } else {
            this.loading = false;

            this.$message({
              message: res.data.message,
              type: "warning",
              center: true
            });
          }
        })
        .catch(err => {
          this.loading = false;

          this.$message.error(err);
        });
    },

    show(id) {
      this.showQr = id;
    },
    showout() {
      this.showQr = 0;
    },
    // 存储空间属性查看,8890
    tickets(id) {
      this.loading = true;

      Tickets(id)
        .then(res => {
          if (res.data.code == 200) {
            this.loading = false;

            this.storageInfo = res.data.data;
            this.dialogVisible = true;
          } else {
            this.loading = false;

            this.Show = false;
            this.$message({
              message: "没有相关数据",
              type: "warning",
              center: true
            });
          }
        })
        .catch(err => {
          this.$message.error(err);
        });
    },

    // 存储空间删除
    isdelete(id, bucketname) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        closeOnClickModal: false,
        closeOnPressEscape: false
      })
        .then(() => {
          this.loading = true;
          IsDelete(id, bucketname)
            .then(res => {
              if (res.data.code == 200) {
                // 这里删除有点慢，加一个加载动画
                this.loading = false;
                this.$message({
                  message: res.data.data,
                  type: "success",
                  center: true
                });

                this.listBockets();
              } else {
                this.loading = false;
                this.$message({
                  message: "删除失败",
                  type: "warning",
                  center: true
                });
              }
            })
            .catch(err => {
              this.$message.error(err);
            });
        })
        .catch(() => {});
    }
    // toto(id) {
    //   this.$router.push({
    //     path: "/home/networkdisk",
    //     query: { id: id }
    //   });
    // }
  },
  mounted() {
    this.listBockets();
  }
};
</script>
<style lang="less" scoped>
.storage_menu {
  width: 100%;
  height: 100%;
  display: flex;
  flex-wrap: wrap;
}
.storage_box {
  width: 300px;
  height: 110px;
  border: 1px solid rgb(56, 161, 237);
  border-radius: 5px;
  margin-right: 16px;
  position: relative;
  // border-color: #fff;
  .storage_box_ul {
    width: 100%;
    height: 100%;
  }
}

.storage_box:hover {
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
}
.storage_box_left {
  // border: 1px solid #000;
  width: 100px;
  height: 100%;
  position: absolute;
  top: 20px;
  left: 8px;
}

.storage_box_right {
  // border: 1px solid #000;
  height: 100%;
  width: 200px;
  position: absolute;
  right: 0;
}
.storage_box_more {
  // border: 1px solid #000;
  width: 50px;
  position: absolute;
  right: 0;
  cursor: pointer;
}
.storage_box_name {
  font-size: 24px;

  text-align: center;
  position: absolute;
  bottom: 40px;
  right: 60px;
  color: rgb(56, 161, 237);
  cursor: pointer;
}
.storage_box_fun {
  > ul > li {
    font-size: 14px;
    margin-bottom: 10px;
    color: rgb(56, 161, 237);
  }
  > ul > li:hover {
    color: #f40;
  }
}

.descriptions {
  margin-top: 30px;
}
</style>